// 弓型布局数据格式
const LEFT_TYPE = 'left'
const RIGHT_TYPE = 'right'
export const getCanvasDataB = (len) => {
  if (!len) {
    return {
      nodes: [],
      edges: []
    }
  }
  const arr = new Array(len).fill({})
  const anchorPoints = [
    [0, 0.5],
    [0.5, 0],
    [1, 0.5],
    [0.5, 1]
  ]
  const leftNodes = []
  const rightNodes = []
  const edges = []
  arr.forEach((_, idx) => {
    // 左侧
    if ([0, 3].includes(idx % 4)) {
      const leftNode = {
        id: `${idx}`,
        label: `L__${idx}`,
        sort: idx + 1,
        cluster: LEFT_TYPE,
        anchorPoints: anchorPoints,
        username: '',
        deviceName: '',
        deviceSn: '',
        type: 'kingCard'
      }
      leftNodes.push(leftNode)
    }
    // 右侧
    if ([1, 2].includes(idx % 4)) {
      const rightNode = {
        id: `${idx}`,
        label: `R__${idx}`,
        sort: idx + 1,
        cluster: RIGHT_TYPE,
        anchorPoints: anchorPoints,
        username: '',
        deviceName: '',
        deviceSn: '',
        type: 'kingCard'
      }
      rightNodes.push(rightNode)
    }
    if (idx !== arr.length - 1) {
      let edge
      if (idx % 4 === 0) {
        edge = {
          source: `${idx}`,
          target: `${idx + 1}`,
          type: 'line',
          style: {
            endArrow: true,
            stroke: '#33a5e2'
          },
          sourceAnchor: 2,
          targetAnchor: 0,
          idx: 'edge' + idx,
          autoDraw: false
        }
      }
      if (idx % 4 === 1) {
        edge = {
          source: `${idx}`,
          target: `${idx + 1}`,
          type: 'line',
          style: {
            endArrow: true,
            stroke: '#33a5e2'
          },
          sourceAnchor: 3,
          targetAnchor: 1,
          idx: 'edge' + idx,
          autoDraw: false
        }
      }
      if (idx % 4 === 2) {
        edge = {
          source: `${idx}`,
          target: `${idx + 1}`,
          type: 'line',
          style: {
            endArrow: true,
            stroke: '#1890ff'
          },
          sourceAnchor: 0,
          targetAnchor: 2,
          idx: 'edge' + idx,
          autoDraw: false
        }
      }
      if (idx % 4 === 3) {
        edge = {
          source: `${idx}`,
          target: `${idx + 1}`,
          type: 'line',
          style: {
            endArrow: true,
            stroke: '#1890ff'
          },
          sourceAnchor: 3,
          targetAnchor: 1,
          idx: 'edge' + idx,
          autoDraw: false
        }
      }
      edges.push(edge)
    }
  })

  return {
    nodes: [...leftNodes, ...rightNodes],
    edges: edges
  }
}
